package main

//#cgo LDFLAGS:
//char* allocMemory();
import "C"
import (
	"fmt"
	"os"
	"strconv"
	"time"
)

func main() {
	// only loop 10 times to avoid exhausting the host memory
	myVar := os.Getenv("CIRCLE_COUNT_TIME")
	var circleTime int
	if myVar == "" {
		circleTime = 5
	} else {
		value, err := strconv.ParseInt(myVar, 10, 64)
		if err != nil {
			circleTime = 5
		} else {
			circleTime = int(value)
		}
	}

	holder := []*C.char{}
	for i := 1; i <= circleTime; i++ {
		fmt.Printf("Allocating %dMb memory, raw memory is %d\n", i*100, i*100*1024*1025)
		// hold the memory, otherwise it will be freed by GC
		holder = append(holder, (*C.char)(C.allocMemory()))
		time.Sleep(3 * time.Second)
	}

	for {
		time.Sleep(10 * time.Second)
		fmt.Println("sleep 10 second.")
	}
	//time.Sleep(365*24*time.Hour)
}
